package org.bite.springmvcdemo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.bite.model.userInfo;

public class JsonController {
    public static void main(String[] args) throws JsonProcessingException {
        //对象转json
        ObjectMapper mapper = new ObjectMapper();
        userInfo user = new userInfo("zhangsan",20,"123456");
        String jsonStr = mapper.writeValueAsString(user);
        System.out.println(jsonStr);
        //json转对象
        String json = "{\"userName\":\"zhangsan\",\"age\":20,\"password\":\"123456\"}";
        userInfo userInfo1 = mapper.readValue(json, userInfo.class);
        System.out.println(userInfo1);
    }
}
